package com.stud.common.core.page;

import cn.hutool.http.HttpStatus;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Getter;
import lombok.Setter;

import java.io.Serializable;
import java.util.List;

/**
 * 表格分页数据对象
 *
 * @author Stud
 */
@Schema(description = "表格分页数据对象")
@Getter
@Setter
public class TableDataInfo<T> implements Serializable {
    @Schema(description = "总记录数")
    private long total;

    @Schema(description = "列表数据")
    private List<T> rows;

    @Schema(description = "消息状态码")
    private int code;

    @Schema(description = "消息")
    private String msg;

    @Schema(description = "分页属性")
    private PageDomain pageDomain;

    /**
     * 表格数据对象
     */
    public TableDataInfo() {
    }

    /**
     * 分页
     *
     * @param list  列表数据
     * @param total 总记录数
     */
    public TableDataInfo(List<T> list, int total) {
        this.rows = list;
        this.total = total;
    }

//    public static <T> TableDataInfo<T> build(IPage<T> page) {
//        TableDataInfo<T> rspData = new TableDataInfo<>();
//        rspData.setCode(HttpStatus.HTTP_OK);
//        rspData.setMsg("查询成功");
//        rspData.setRows(page.getRecords());
//        rspData.setTotal(page.getTotal());
//        return rspData;
//    }

    public static <T> TableDataInfo<T> build(List<T> list) {
        TableDataInfo<T> rspData = new TableDataInfo<>();
        rspData.setCode(HttpStatus.HTTP_OK);
        rspData.setMsg("查询成功");
        rspData.setRows(list);
        rspData.setTotal(list.size());
        return rspData;
    }

    public static <T> TableDataInfo<T> build() {
        TableDataInfo<T> rspData = new TableDataInfo<>();
        rspData.setCode(HttpStatus.HTTP_OK);
        rspData.setMsg("查询成功");
        return rspData;
    }


}
